<?php

global $usuario;

//$usuario =5;
//$usuario= $row["usuario"];


 //$vars = get_defined_vars();   
 //print_r($vars);   

 
 //echo "Upload: " . $HTTP_POST_VARS["fileId"] . "<br />"; 
  //echo "Upload: " . $HTTP_POST_VARS["usuario"] . "<br />"; 
  
  //echo "Upload: " . $HTTP_GET_VARS["fileId"]. "<br />";
 
 $usuario=  $HTTP_GET_VARS["fileId"];

//if(!is_numeric($usuario))

//die("Invalid usuario specified");

// Database connection variables

$dbServer = "acuario.ecci.ucr.ac.cr";

$dbDatabase = "bdusj2";

$dbUser = "us2";

$dbPass = "usj2";



$sConn = mysql_connect($dbServer, $dbUser, $dbPass)

or die("Couldn't connect to database server");



$dConn = mysql_select_db($dbDatabase, $sConn)

or die("Couldn't connect to database $dbDatabase");



$dbQuery = "SELECT TipoFoto, Foto ";

$dbQuery .= "FROM Foto ";

$dbQuery .= "WHERE IDUsuario = $usuario";

$result = mysql_query($dbQuery) or die("Couldn't get file list");



if(mysql_num_rows($result) == 1)

{

$fileType = @mysql_result($result, 0, "TipoFoto");

$fileContent = @mysql_result($result, 0, "Foto");



header("Content-type: $fileType");

echo $fileContent;

}

else

{

echo "Record doesn't exist.";

}

?>